# coding: utf-8
from sqlalchemy import Column, String
from sqlalchemy.dialects.mysql import BIGINT
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class FsmRecord(Base):
    __tablename__ = 'fsm_record'
    __table_args__ = {'comment': '记录表'}

    id = Column(BIGINT(20), primary_key=True, comment='自增id')
    record_id = Column(String(255), nullable=False, unique=True, comment='id')
    cur_node = Column(String(255), nullable=False, comment='当前节点')
    status = Column(String(255), nullable=False, comment='节点状态')
    exec_times = Column(BIGINT(20), nullable=False, comment='执行次数')
    lock_time = Column(BIGINT(20), nullable=False, comment='是否锁定，0：未锁定，非0：锁定的时间戳')
    next_exec_time = Column(BIGINT(20), nullable=False, comment='下次执行时间')
    mode = Column(String(255), nullable=False, comment='订单推送模式')


class Worker(Base):
    __tablename__ = 'workers'
    __table_args__ = {'comment': '工作线程表'}

    id = Column(BIGINT(20), primary_key=True, comment='自增id')
    worker_id = Column(String(255), nullable=False, comment='id')
    checkin_time = Column(BIGINT(20), nullable=False, comment='打卡时间')
    shards_id = Column(BIGINT(20), nullable=False, comment='分片id')
    sharding_range = Column(BIGINT(20), nullable=False, comment='分片范围')
